using System;
using System.Reflection;
using BitMango.Diagnostics;
using HCP.Responses;
using HCP.SimpleJSON;

namespace HCP.Requests
{
	public class CallStatic : JobRequest
	{
		public CallStatic(JSONClass json) : base(json)
		{
		}

		public string Class
		{
			get
			{
				return base.Data["class"];
			}
		}

		public string Method
		{
			get
			{
				return base.Data["method"];
			}
		}

		public override JobResponse Process()
		{
			Type type = Type.GetType(this.Class);
			Debugger.Assert(type != null, "type not found : " + this.Class);
			MethodInfo method = type.GetMethod(this.Method);
			Debugger.Assert(method != null, "method not found : " + this.Method);
			ParameterInfo[] parameters = method.GetParameters();
			object[] array = new object[parameters.Length];
			for (int i = 0; i < parameters.Length; i++)
			{
				string aKey = "p" + (i + 1);
				string text = base.Data[aKey];
				ParameterInfo parameterInfo = parameters[i];
				if (parameterInfo.ParameterType == typeof(string))
				{
					array[i] = text;
				}
				else
				{
					array[i] = null;
				}
			}
			object obj = method.Invoke(null, array);
			if (obj != null)
			{
				return new StringResponse(obj.ToString());
			}
			return new StringResponse();
		}
	}
}
